<template>
    <div class="">
        <el-dialog title="批量添加卫生费" :visible.sync="dialog" width="40%" :before-close="dialogClose">
            <el-form ref="formData" :model="formData" label-width="100px">
				<el-form-item label="年份(年)" prop="amount">
					<el-date-picker
					  v-model="formData.date"
					  type="year"
					  value-format="yyyy"
					  placeholder="请输入年份">
					</el-date-picker>
				</el-form-item>
				<el-form-item label="卫生费人均" prop="title">
				    <el-input type="number" v-model="formData.precapita" placeholder="请输入卫生费人均多少钱"></el-input>
				</el-form-item>
				<el-form-item label="卫生费最低" prop="title">
				    <el-input type="number" v-model="formData.lowest" placeholder="请输入卫生费最低多少钱"></el-input>
				</el-form-item>
            	<el-form-item>
            		<el-button @click="dialogClose">取 消</el-button>
            		<el-button type="primary" @click="formSubmit">确 定</el-button>
            	</el-form-item>
            </el-form>
        </el-dialog>
    </div>
</template>
<script>
    export default {
        data() {
			return {
				dialog: false,
				formData: {
				},
				config:{}
			}
        },
		created() {
			
		},
		watch: {
			dialog () {
				if(!this.dialog) {
					this.clearFormData()
					this.$emit('getHygieneFee')
				} else {
					this.getConfig()
				}
			}
		},
        methods: {
			getConfig () {
				this.$apiPost('Config/infos').then(res => {
					if(res.code == 1) {
						this.config = res.data
						this.$set(this.formData,'precapita',res.data.perCapita)
						this.$set(this.formData,'lowest',res.data.lowest)
						// this.formData.precapita = res.data.perCapita
						// this.formData.lowest = res.data.lowest
					}
				})
			},
			dialogClose(){
				this.$emit('dialogToggle4')
			},
			clearFormData () {
				for(let i in this.formData){
					if(i == 'id') {
						this.formData[i] = 0
					} else {
						this.formData[i] = ''
					}
				}
			},
			// 保存编辑
			formSubmit() {
				if(!this.formData.date){
					return this.$message.error('请选择年份')
				}
				if(!this.formData.lowest||this.formData.lowest<=0){
					return this.$message.error('最低卫生费输入错误')
				}
				if(!this.formData.precapita||this.formData.precapita<=0){
					return this.$message.error('人均费用输入错误')
				}
				this.$apiPost('HygieneFee/batchAdd', this.formData).then(res => {
					if(res.code == 1) {
						this.$message(res.msg)
						this.dialogClose()
					} else {
						this.$message(res.msg)
					}
				})
			},
        }
    };
</script>
<style scoped>
	.mselect{
		width: 100%;
	}
	.mtdiv{
		margin-top: 10px;
		display: inline-block;
		width: 100%;
	}
	.mtdiv .mtdiv-v{
		float: left;
		width: 50%;
		margin-bottom: 5px;
		display: flex;
		align-items: center;
	}
	.mtdiv .mtdiv-v label{
		float: left;
		margin-right: 10px;
	}
	.mtdiv .el-input{
		float: left;
		width: 80%;
		margin: 5px 0;
	}
	.el-cascader {
		line-height: 32px !important;
	}
	.el-input__inner {
	    height: 32px !important;
	    line-height: 32px !important;
	}
	.el-input__icon {
		line-height: 32px !important;
	}
</style>
